﻿package{
	import flash.display.*;
	import flash.events.*;
	import flash.utils.Dictionary;
	import flash.events.Event;
	import covert;
	public class animation extends Bitmap{
		var speed:Number,len:int;
		var count:Number = 0,point:int = 0;
		var par,end:Function;
		var content:Array;
		function animation(pic:Bitmap,col:int,row:int,valid = null){
			content = covert.divide(pic,col,row,valid);
			len = content.length;
			bitmapData = content[0];
		}
		function setDuration(par,duration){
			this.par = par;
			speed = len/(par.stage.frameRate*duration)
		}
		function start(){
			x -= width/2
			y -= height*0.7
			par.addChild(this);
			addEventListener(Event.ENTER_FRAME,enterFrame);
		}
		function enterFrame(e:Event){
			count += speed;
			point += int(count)
			count = count%1;
			bitmapData = content[point < len ? point : len - 1];
			if(point >= len){
				removeEventListener(Event.ENTER_FRAME,enterFrame);
				par.removeChild(this);
				if(end != null)end();
			}
		}
	}
}